package com.liyunc.demo.bundle.file.manager.utils.converter;

import com.liyunc.demo.bundle.file.manager.model.dto.output.AssetFileDto;
import com.liyunc.demo.bundle.file.manager.model.entity.AssetFile;
import org.mapstruct.Mapper;

@Mapper
public interface AssetFileConverter {

    Integer DEFAULT_VERSION = 1;
    String DEFAULT_MIME_TYPE = "application/octet-stream";

    AssetFileDto forEntity(AssetFile entity);

    default AssetFile fromUpload(
        String filename,
        String filepath,
        String mimeType,
        Integer ownerType,
        Long ownerId,
        String checksum
    ) {
        AssetFile entity = new AssetFile();
        entity.setFilename(filename);
        entity.setFilepath(filepath);
        entity.setMimeType(mimeType == null ? DEFAULT_MIME_TYPE : mimeType);
        entity.setOwnerType(ownerType);
        entity.setOwnerId(ownerId);
        entity.setChecksum(checksum);
        entity.setVersion(DEFAULT_VERSION);
        return entity;
    }
}
